"use strict";

angular.module('app.configService').controller('SystemCtrl', function ($scope,userHttpS,$rootScope,$cookieStore) {


	$('#yyzz_img').click(function(){
		$('#file').modal('show')
	});
	$("#file-cad").fileinput({
		language: 'zh',
		uploadUrl: 'http://172.31.181.173:9061/postfiles/upload',
		allowedFileExtensions: ['doc', 'docx', 'pdf','png','jpg'],
		overwriteInitial: false,
		maxFileSize: 1000,
		maxFilesNum: 10,
		showPreview: true,
		// uploadExtraData:{
		//    id: 100,
		//    type: "product" //是上传的产品图
		// }
		ajaxSettings:{
			beforeSend:function(xhr){
				xhr.setRequestHeader('token',custom.token);
			}
		}
	});
	$scope.src ={};

	$("#file-cad").on("fileuploaded", function (event, data, previewId, index) {

		if(data.response!= null){
			console.log("上传成功");
			$scope.src.serversrc= data.response.result;
			$scope.src.file =data.files[0];
			$scope.src.filename =data.files[0].name;
			$scope.src.filesize =data.files[0].size;
			$scope.src.filetype =data.files[0].type;
			var head_pro_id = $cookieStore.get('project_id');
			$scope.src.proid = head_pro_id;
			console.log($scope.src.serversrc);
			documentHttpS.postAll("uploadtoserver",$scope.src).then(function (response) {

				console.log(response);

			})

		}else{
			console.log("上传失败")
		}

	});



	$('#com_logo').click(function(){
		$('#file1').modal('show')
	});
	$("#file-cad1").fileinput({
		language: 'zh',
		uploadUrl: 'http://172.31.181.173:9061/postfiles/upload',
		allowedFileExtensions: ['doc', 'docx', 'pdf','png','jpg'],
		overwriteInitial: false,
		maxFileSize: 1000,
		maxFilesNum: 10,
		showPreview: true,
		// uploadExtraData:{
		//    id: 100,
		//    type: "product" //是上传的产品图
		// }
		ajaxSettings:{
			beforeSend:function(xhr){
				xhr.setRequestHeader('token',custom.token);
			}
		}
	});

	$("#file-cad1").on("fileuploaded", function (event, data, previewId, index) {

		if(data.response!= null){
			console.log("上传成功");
			$scope.src.serversrc= data.response.result;
			$scope.src.file =data.files[0];
			$scope.src.filename =data.files[0].name;
			$scope.src.filesize =data.files[0].size;
			$scope.src.filetype =data.files[0].type;
			var head_pro_id = $cookieStore.get('project_id');
			$scope.src.proid = head_pro_id;
			console.log($scope.src.serversrc);
			documentHttpS.postAll("uploadtoserver",$scope.src).then(function (response) {

				console.log(response);

			})

		}else{
			console.log("上传失败")
		}

	});

    // HTTPDataService.getSystemConfig().then(function (response) {

    //     $scope.systemInfo = response;

    //     $scope.save = function () {

    //         HTTPDataService.postSysInfo($scope.systemInfo);
    //         HTTPDataService.setSystemConfig();
    //         $.smallBox({
    //             title: "设置成功",
    //             content: "<i class='fa fa-clock-o'></i> <i>设置成功</i>",
    //             color: "#659265",
    //             iconSmall: "fa fa-check fa-2x fadeInRight animated",
    //             timeout: 4000
    //         });

    //     }

	// });
	
	userHttpS.get("getcompanyinfo").then(function(response){
		$scope.company_info = response;
	    console.log(response);
		console.log($scope.company_info.id)
	});
	      

	$scope.btn_save_name2= function(){
	        userHttpS.post("companyAuth",$scope.company_info).then(function(response){
	        	console.log(response);
	            if(response==1){
	            	$(".ti7").html("<font color=\"green\" size=\"2\">保存成功</font>"); 
	            }else{
	            	$(".ti7").html("<font color=\"red\" size=\"2\">保存失败</font>"); 
	            }
	        });
	    }
});